package activity.driverrepair;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.hutoubenjg.R;

import java.util.ArrayList;
import java.util.List;

import base.BaseActivity;
import fragment.OrderFragemnt;
import fragment.OrdersFragemnt;
import util.utls.UIAlertView;

/**
 * 维修
 */
public class DriverRepair extends BaseActivity{
    TextView btn_head_a, btn_head_b;
    List<Fragment> fragments = new ArrayList<>();
    public ViewPager viewPager;
    private ImageView imgMessge, imgProalin;
    UIAlertView uiAlertView;
    Button noBtnLong;
    public static DriverRepair act;

    public static DriverRepair onSetFragment() {
        return act;
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_driver_repair);
        act = this;
        OrdersFragemnt repairFragment = new OrdersFragemnt();
        OrderFragemnt orderTvFragment = new OrderFragemnt();
        setStatusBarColor(R.color.main_color);
        fragments.add(repairFragment);
        fragments.add(orderTvFragment);
        viewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), fragments));
        viewPager.setCurrentItem(0);
        changeTextBG(0);
        btn_head_b.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("btn_head_b", "b");
                viewPager.setCurrentItem(1);
            }
        });
        btn_head_a.setOnClickListener(this);

        viewPager.setOnPageChangeListener(new myPagerListener());

    }

    private void changeTextBG(int position) {
        switch (position) {
            case 0:
                btn_head_a.setBackgroundResource(R.drawable.house_rent_selected);
                btn_head_b.setBackgroundColor(getResources().getColor(R.color.gray_divider));
                btn_head_a.setTextColor(getResources().getColor(R.color.white));
                btn_head_b.setTextColor(getResources().getColor(R.color.black));
                break;
            case 1:
                btn_head_b.setTextColor(getResources().getColor(R.color.white));
                btn_head_a.setTextColor(getResources().getColor(R.color.black));
                btn_head_b.setBackgroundResource(R.drawable.house_center_selected);
                btn_head_a.setBackgroundColor(getResources().getColor(R.color.gray_divider));
                break;
        }

    }
    @Override
    protected void onInit() {

    }

    @Override
    protected void onReadIntent(Bundle bundle) {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_head_a:
                viewPager.setCurrentItem(0);
                Log.d("btn_head_a", "a");
                break;
            case R.id.btn_head_b:
                Log.d("btn_head_b", "b");
                viewPager.setCurrentItem(1);
                break;
        }
    }
    class MyPagerAdapter extends FragmentStatePagerAdapter {
        List<Fragment> fragments;

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        public MyPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
            super(fm);
            this.fragments = fragments;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }
    }
    class myPagerListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            viewPager.setCurrentItem(position);
            changeTextBG(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    }
}
